<?php

require_once dirname(__FILE__).'/../lib/preciosxmodelosGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/preciosxmodelosGeneratorHelper.class.php';

/**
 * preciosxmodelos actions.
 *
 * @package    gescell
 * @subpackage preciosxmodelos
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class preciosxmodelosActions extends autoPreciosxmodelosActions
{
    public function executeEdit(sfWebRequest $request)
  {
    $this->preciosxmodelos = $this->getRoute()->getObject();
    $this->form = $this->configuration->getForm($this->preciosxmodelos);

    $modelos_id = $this->preciosxmodelos->getModelosid();
    $this->redirect('modelos/ListPrecios?id='.$modelos_id);

    /*$criteria = new Criteria();
    $criteria->add(preciosxmodelosPeer::MODELOS_ID,$modelos_id);
    $this->form->det = new preciosxmodelos();
    $this->form->det = preciosxmodelosPeer::doSelect($criteria);*/
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form            = $this->configuration->getForm();
    $this->preciosxmodelos = $this->form->getObject();
  }




  public function executeAutocompletar(){

      $this->forward404Unless($this->getRequest()->isXmlHttpRequest());
      $this->getResponse()->setContentType('application/json');
      $modelos = modelosPeer::ResultadosAutoCompletado($this->getrequest()->getParameter('q'), $this->getrequest()->getParameter('limit'));
      return $this->renderText(json_encode($modelos));
  }
  public function executeAgregar_con_ajax(){
      $this->forward404Unless($this->getRequest()->isXmlHttpRequest());
      $precios_id = $this->getRequest()->getParameter('listadeprecios_id');
      $modelos_id = $this->getRequest()->getParameter('modelo_id');
      if (!preciosxmodelosPeer::ClaveRepetida($modelos_id, $precios_id)){
              $preciosxmodelos=new preciosxmodelos();
              $preciosxmodelos->setListadepreciosId($precios_id);
              $preciosxmodelos->setmodelosid($modelos_id);
              $preciosxmodelos->setprecio($this->getRequest()->getParameter('precio'));
              $preciosxmodelos->setiva($this->getRequest()->getParameter('iva'));
              $preciosxmodelos->save();
              $criteria = new Criteria();
              $criteria->add(preciosxmodelosPeer::MODELOS_ID,$this->getRequest()->getParameter('modelo_id'));
              $this->form = new preciosxmodelosForm();
              $this->form->det = new preciosxmodelos();
              $this->form->det = preciosxmodelosPeer::doSelect($criteria);
              return $this->renderPartial('detalles', array('form' => $this->form));
      }
      else{
          $this->getResponse()->setStatusCode(404);
          return $this->renderText('Dato Repetido');
      }

  }
  public function executeEditar_datos_ajax(sfWebRequest $request){
         $this->forward404Unless($this->getRequest()->isXmlHttpRequest());      
         $precios_id = $this->getRequest()->getParameter('listadeprecios_id');
         $modelos_id = $this->getRequest()->getParameter('modelo_id');
         $c = new criteria;
         $c->add(preciosxmodelosPeer::LISTADEPRECIOS_ID,$precios_id);
         $c->add(preciosxmodelosPeer::MODELOS_ID,$modelos_id);
         $preciosxmodelos=new preciosxmodelos();
         $preciosxmodelos = preciosxmodelosPeer::doSelectOne($c);
         $preciosxmodelos->setprecio($this->getRequest()->getParameter('precio'));
         $preciosxmodelos->setiva($this->getRequest()->getParameter('iva'));
          $preciosxmodelos->save();
              $criteria = new Criteria();
              $criteria->add(preciosxmodelosPeer::MODELOS_ID,$this->getRequest()->getParameter('modelo_id'));
              $this->form = new preciosxmodelosForm();
              $this->form->det = new preciosxmodelos();
              $this->form->det = preciosxmodelosPeer::doSelect($criteria);
              return $this->renderPartial('detalles', array('form' => $this->form));
      
      //else{
      //    $this->getResponse()->setStatusCode(404);
      //    return $this->renderText('Dato Repetido');
      
  }
}
